﻿Public Class ReportUT517
	Inherits System.Web.UI.Page

	Private Property DataSource As Data.DataTable
		Get
			Return Me.Session("datasourceut514")
		End Get
		Set(ByVal value As Data.DataTable)
			Me.Session("datasourceut514") = value
		End Set
	End Property

	Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

	End Sub

	Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSearch.Click
		Dim dteFrom As String = Nothing
		Dim dteTo As String = Nothing

		If Not String.IsNullOrEmpty(Me.fromDate.value) Then
			dteFrom = New DateTime(Me.fromDate.Year, Me.fromDate.Month, Me.fromDate.Day).AddYears(-543).ToString("yyyyMMdd")
		End If

		If Not String.IsNullOrEmpty(Me.toDate.value) Then
			dteTo = New DateTime(Me.toDate.Year, Me.toDate.Month, Me.toDate.Day).AddYears(-543).ToString("yyyyMMdd")
		End If

		DataSource = BL.Report.ReportUT517(dteFrom, dteTo, Me.ddlFileType.SelectedItem.Value, Me.ddlTranStatus.SelectedItem.Value, Me.txtTel.Text)

		Bind(0)
	End Sub

	Private Sub Bind(ByVal pageIndex As Integer)
		Me.gvList.DataSource = DataSource
		Me.gvList.PageIndex = pageIndex
		Me.gvList.DataBind()
	End Sub

	Protected Sub btnReset_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnReset.Click
		Me.Session.Remove("datasourceut517")
		Response.Redirect("ReportUT517.aspx", False)
	End Sub

	Private Sub gvList_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvList.PageIndexChanging
		Bind(e.NewPageIndex)
	End Sub

	Protected Sub btnExcel_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnExcel.Click
		If Me.DataSource Is Nothing OrElse Me.DataSource.Rows.Count = 0 Then
			Exit Sub
		End If

		Dim dt As DataTable = Me.DataSource
		dt.Columns.Add("OrderNo")
		Dim i As Integer = 0
		For Each dr As DataRow In dt.Rows
			i += 1
			dr("OrderNo") = i.ToString
		Next
		Common.Utility.ExportToSpreadsheet(gvList, dt, "InterfaceTransaction")
	End Sub

	Public Shared Function OrderNuber() As String
		Return String.Empty
	End Function

End Class